package org.web.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import org.primefaces.event.RowEditEvent;
import org.service.StudyService;
import org.entity.Patient;
import org.entity.Study;

@SuppressWarnings("unused")
public class StudyBean {
	
	private Study study;
	
	private Integer pat_pk;
	
	//private List<Study> allstudy;
	
	private UIData table;
	
	private StudyService service;
	
	public StudyBean(){
		
		service = new StudyService();
		
		FacesContext fc = FacesContext.getCurrentInstance();
		@SuppressWarnings("rawtypes")
		Map requestParams = fc.getExternalContext().getRequestParameterMap();
		Integer pat_pk = Integer.parseInt((String)fc.getExternalContext().getRequestParameterMap().get("pat_pk")); 
		//Integer pat_pk = (Integer) requestParams.get("pat_pk");
		this.pat_pk = pat_pk;
	}
	 
	
	public List<Study> getAllStudy(){
		return this.service.findAllStudy();
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public ListDataModel getStudyByPatientPk() {
		return new ListDataModel(this.service.findStudyByPatientPk(pat_pk));
	}
	
	public Study getStudy() {
		return study;
	}

	public void setStudy(Study study) {
		this.study = study;
	}

	public UIData getTable() {
		return table;
	}

	public void setTable(UIData table) {
		this.table = table;
	}
	
	public String updateAction(){
		this.service.update(study);
		return "updated";
	}

	/**public void onEditRow(RowEditEvent event) {
		Study stu = (Study) event.getObject();
		service.update(stu);
		allstudy = this.service.findAllStudy();
	}*/
}

